package thermologic.core;

import thermologic.onewire.DeviceStatusOWC;

/**
 * Thread for perform asynchronous setup of a device
 * 
 * @author Mauricio Rivadeneira S
 */
public class DeviceSetupThread implements Runnable
{
    private Adapter adapter;
    
    private Device device;

    /**
     * Create an instance of DeviceSetupThread, this
     * thread executes the setup using the adapter object
     * 
     * @param adapter Adapter used 
     * @param device Device to be setup
     */
    public DeviceSetupThread(Adapter adapter, Device device)
    {
        if(adapter == null)
        {
            throw new IllegalArgumentException("Adapter is null");
        }
        
        if(device == null)
        {
            throw new IllegalArgumentException("Device is null"); 
        }
        
        this.adapter = adapter;
        this.device = device;
    }
    
    @Override
    public void run()
    {
        adapter.connectAndSetup(device);
    }
    
    /**
     * Main method for test purposes
     * 
     * @param args
     */
    public static void main(String args[])
    {
        Datalogger datalogger = new Datalogger(
                "FA00000017C12A21",
                DeviceType.DATALOGGER_IBUTTON_FAMILY_21,
                "",
                DeviceStatusOWC.NO_MISSION,
                true
                );
        
        AdapterFactory.getAdapter().connectAndSetup(datalogger);
    }
    
}
